<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>远程发券</title>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <link rel="shortcut icon" href="favicon.ico"> <link href="${pageContext.request.contextPath}/resources/plugins/h+/css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/resources/plugins/h+/css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/resources/plugins/h+/css/style.min862f.css?v=4.1.0" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/resources/plugins/h+/css/plugins/chosen/chosen.css" rel="stylesheet">
    <script src="${pageContext.request.contextPath}/resources/plugins/h+/js/jquery.min.js?v=2.1.4"></script>
    <script src="${pageContext.request.contextPath}/resources/plugins/h+/js/plugins/validate/jquery.validate.min.js"></script>


</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>远程发券</h5>
                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                    </div>
                </div>
                <div class="ibox-content">
                    <form class="form-horizontal m-t" id="signupForm">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">券种：</label>
                            <div class="col-sm-4">
                                <select  id="select_ticketType" name="ticketType" data-placeholder="选择券种..." class="select2 form-control" style="width:100%" tabindex="1" >
                                    <option value="0">久零券</option>
                                    <option value="1">零购券</option>
                                    <option value="2">体验券</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">手机号码：</label>
                            <div class="col-sm-4">
                                <input id="txt_phone" name="phone" class="form-control" type="text">
                                <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 请输入手机号</span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">券额(元)：</label>
                            <div class="col-sm-4">
                                <input id="txt_gift_total" name="total" class="form-control" type="text" aria-required="true" aria-invalid="false" class="valid">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-8 col-sm-offset-3">
                                <button class="btn btn-primary" type="button" id="btn_save" onclick="doSave();"><i class="fa fa-check"></i> 确定</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>


<script src="${pageContext.request.contextPath}/resources/plugins/h+/js/bootstrap.min.js?v=3.3.6"></script>
<script src="${pageContext.request.contextPath}/resources/plugins/h+/js/content.min.js?v=1.0.0"></script>
<script src="${pageContext.request.contextPath}/resources/plugins/h+/js/demo/form-validate-demo.min.js"></script>
<script src="${pageContext.request.contextPath}/resources/plugins/h+/js/plugins/layer2.4/layer.js"></script>
<script src="${pageContext.request.contextPath}/resources/plugins/h+/js/plugins/chosen/chosen.jquery.js"></script>
<script type="text/javascript" src="http://tajs.qq.com/stats?sId=9051096" charset="UTF-8"></script>
<script>
    /*$("#select_ticketType").val(0);
    $("#select_ticketType").trigger("chosen:updated");*/
    function doSave()
    {
        var isPass = true;
        isPass = validateNull($("#txt_phone"), isPass,"请填写手机号码!");
        isPass = validateNull($("#txt_gift_total"), isPass,"请填写劵额!");
        var phone=$("#txt_phone").val();
        var total=$("#txt_gift_total").val();
        var ticketType=$("#select_ticketType").val();
        if (isPass == true)
        {
            var exp = /^([1-9][\d]{0,7}|0)(\.[\d]{1,2})?$/;
            if(!exp.test(total)){
               alert("请输入正确的劵额");
            }else{
                var url = "${pageContext.request.contextPath}/orderStatistics/doIssuedGift.ac";
                $.ajax({
                    type: "post",
                    url: url,
                    data: {ticketType:ticketType,phone:phone,total:total},
                    dataType: 'json',
                    success: function(data) {
                        if(data.isok == true){
                            alert(data.msg);
                            window.location.href="${pageContext.request.contextPath}/orderStatistics/toIssuedGift.ac";
                        }else{
                            alert(data.msg);
                        }
                    }
                });
            }

        }
    }


    function validateNull(obj,isPass,error_info)
    {
        if(obj.val()=="")
        {
            isPass = false;
            showError(obj,error_info);
        }
        else
        {
            closeError(obj);
        }
        return isPass;
    }

    function showError(obj,error_info)
    {
        if(obj.closest('.form-group').hasClass('has-error') == false)
        {
            obj.parent().after("<div class='help-block'>"+error_info+"</div>");
            obj.closest('.form-group').removeClass('has-info').addClass('has-error');
        }
    }
    function closeError(obj)
    {
        if(obj.closest('.form-group').hasClass('has-error') == true)
        {
            obj.closest('.form-group').removeClass('has-error');//.addClass('has-info');
            obj.parent().next().remove();
        }
    }
</script>

</body>

</html>

